package com.jerry.mingxing.ui.fashionrecommend;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.NewBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/9/1.
 */
public class FashionRecommendNewAdapter extends BaseAdapter {
    private List<NewBean.ResponseBean.DataBean.ItemsBean> list;
    private Context mContext;
    private LayoutInflater inflater;

    public FashionRecommendNewAdapter(List<NewBean.ResponseBean.DataBean.ItemsBean> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
        this.inflater = LayoutInflater.from(mContext);

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.newfragment_gridview_item, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.newTextviewItemContenttitle.setText(list.get(position).getComponent().getContent());
        holder.newGridviewItemHeadname.setText(list.get(position).getComponent().getUser().getUsername());
        holder.newGridviewItemHeartcount.setText(list.get(position).getComponent().getCollect_count());
        holder.newGridviewItemContentimg.setImageURI(Uri.parse(list.get(position).getComponent().getPics()));
        holder.newGridviewItemHeadimg.setImageURI(Uri.parse(list.get(position).getComponent().getUser().getUserAvatar()));
        return view;
    }

    static class ViewHolder {
        @Bind(R.id.new_gridview_item_contentimg)
        SimpleDraweeView newGridviewItemContentimg;
        @Bind(R.id.new_textview_item_contenttitle)
        TextView newTextviewItemContenttitle;
        @Bind(R.id.new_gridview_item_headimg)
        SimpleDraweeView newGridviewItemHeadimg;
        @Bind(R.id.new_gridview_item_headname)
        TextView newGridviewItemHeadname;
        @Bind(R.id.new_gridview_item_goodheart)
        ImageView newGridviewItemGoodheart;
        @Bind(R.id.new_gridview_item_heartcount)
        TextView newGridviewItemHeartcount;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
